#include <functional>
#include <iostream>
#include <thread>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include "xlinkHS.h"
#include "rtk.h"

int main()
{
	unsigned char p_buff[1024] = {0};
	unsigned char p_tmp[] = {0x80, 0x00, 0x90, 0x00, 0x24, 0x00, 0x1f, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x47, 0x84, 0x00, 0x09, 0x00, 0x01, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x68, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x02, 0x15, 0x0c, 0xfe, 0x48, 0x5a, 0x5c, 0x40, 0xbe, 0xf6, 0xbd, 0x3e, 0xda, 0x2d, 0x37, 0x40, 0x00, 0xe0, 0x13, 0xe7, 0x6f, 0xfb, 0xd5, 0x40, 0x09, 0x18, 0x5b, 0x3c, 0x7c, 0x5e, 0xf5, 0x3c, 0xed, 0xb6, 0xd0, 0xc0, 0x9c, 0xfb, 0x39, 0x15, 0xc7, 0x08, 0x01, 0x00, 0x1e, 0x0f, 0x04, 0x01, 0x1d, 0x00, 0x00, 0x00, 0xbf, 0x00, 0x00, 0x00, 0x32, 0x03, 0xc8, 0x00, 0x94, 0x33, 0x23, 0x15, 0xc7, 0x08, 0x68, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1e, 0x0f, 0x00, 0x00, 0x09, 0x0d, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x7e};

	unsigned char e_tmp[] = {0x80, 0x00, 0x58, 0x00, 0x24, 0x00, 0x1f, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b, 0xce, 0x4c, 0x00, 0x09, 0x00, 0x01, 0x03, 0x00, 0x25, 0xc7, 0x08, 0x2d, 0x00, 0x0b, 0x6f, 0x05, 0x00, 0x08, 0x7c, 0x35, 0x28, 0x00, 0x00, 0x00, 0x00, 0x08, 0x7c, 0x35, 0x28, 0x53, 0x67, 0xad, 0x3f, 0xda, 0x2d, 0x37, 0x40, 0x58, 0xaf, 0x32, 0xfe, 0x48, 0x5a, 0x5c, 0x40, 0x00, 0x00, 0x04, 0x4f, 0x75, 0x81, 0x36, 0x40, 0x86, 0x39, 0xeb, 0x3c, 0x4a, 0x3f, 0x0c, 0x3d, 0xb7, 0xeb, 0x4d, 0x3d, 0x11, 0xaa, 0x81, 0x3b, 0xb0, 0x6a, 0x71, 0x3d, 0xd2, 0x32, 0xe1, 0xbd, 0x06, 0x1e, 0x0f, 0x00, 0x00, 0x01, 0x00, 0x1b, 0x4d, 0xa0};

	udp_init();

	while (1) {
		rtk_cmd_package(p_buff, 0, CMD_RTK_BASE_STATION_STATUS);
		package_0x80(p_buff, sizeof(Rtk_0x5B_Header_T));
		//printf("%d\n", sizeof(Station_Status_T));

		sleep(1);
		break;
    }

	/* test analysis function */
	analysis(p_tmp, sizeof(p_tmp));
	analysis(e_tmp, sizeof(e_tmp));

	return 0;
}
